package spynx.desl.runtime.operators.impl;

import spynx.desl.runtime.IExecutionContext;
import spynx.desl.runtime.IInvocator;
import spynx.desl.runtime.IOperator;

public class InvocationOperator implements IOperator {

	@Override
	public String getOperator() {
		return "(";
	}

	@Override
	public Object apply(IExecutionContext context, String operator,
			Object... args) {
		Object medinfo = context.resolveValue(args[0]);
		if (medinfo instanceof IInvocator) {
			Object[] oArgs = new Object[args.length-1];
			for (int i = 0; i<args.length-1; i++)
				oArgs[i] = context.resolveValue(args[i+1]);
			return ((IInvocator) medinfo).invoke(oArgs);
		}
		return null;
	}

}
